package org.lmind.example.common.web.internal;

import java.util.Enumeration;
import java.util.Map;

import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;

import org.apache.commons.collections.iterators.IteratorEnumeration;

@SuppressWarnings("rawtypes")
public class FilterConfigWrapper implements FilterConfig {
	
	private FilterConfig filterConfig;
	
	private String filterName;
	
	private Map<String, String> initParameter;

	/**
	 * @param filterConfig
	 */
	public FilterConfigWrapper(FilterConfig filterConfig) {
		this.filterConfig = filterConfig;
	}

	public void setInitParameter(Map<String, String> initParameter) {
		this.initParameter = initParameter;
	}

	public void setFilterName(String filterName) {
		this.filterName = filterName;
	}

	public String getFilterName() {
		if (filterName != null)
			return filterName;
		else
			return filterConfig.getFilterName();
	}

	public ServletContext getServletContext() {
		return filterConfig.getServletContext();
	}

	public String getInitParameter(String name) {
		if (initParameter != null)
			return initParameter.get(name);
		else
			return filterConfig.getInitParameter(name);
	}

	public Enumeration getInitParameterNames() {
		if (initParameter != null) {
			return new IteratorEnumeration(initParameter.keySet().iterator());
		} else {
			return filterConfig.getInitParameterNames();
		}
	}
}
